import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'
// import path from 'path'

// https://vite.dev/config/
export default defineConfig({
  plugins: [vue(), vueDevTools()],
  resolve: {
    //配置根路径别名
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
      // '&': path.resolve(__dirname, './public'),
    },
  },
  server: {
    proxy: {
      '/api': {
        target: 'http://localhost:3000', //目标服务器地址
        changeOrigin: true, //是否跨域,是否改变请求头中的origin,默认为false
        rewrite: (path) => path.replace(/^\/api/, '/'), //重写路径
      },
    },
  },
})
